//
//  ForgetZFPassViewController.m
//  Vpay
//
//  Created by 伟大大 on 2018/10/22.
//  Copyright © 2018年 丁伟佳. All rights reserved.
//

#import "ForgetZFPassViewController.h"
#import "LoginViewController.h"
@interface ForgetZFPassViewController ()

@end

@implementation ForgetZFPassViewController

#pragma mark -
#pragma mark - for lifeCircle
#pragma mark -
- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    //    [self.navigationController setNavigationBarHidden:YES animated:NO];
    
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    //    [self.navigationController setNavigationBarHidden:NO animated:NO];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"找回支付密码";
    
    self.view = [[[NSBundle mainBundle]loadNibNamed:@"ForgetZFPassViewController" owner:self options:nil]lastObject];
    self.view.backgroundColor = BACKCOLOR;
    
    
    
    //    [self initData];
    [self initNavBtns];
    [self initViews];
    
    //    [NSThread detachNewThreadSelector:@selector(requestData) toTarget:self withObject:nil];
    
    //    [NSThread detachNewThreadSelector:@selector(requestDingdanData) toTarget:self withObject:nil];
}
#pragma mark -
#pragma mark - for Views
#pragma mark -

- (void)initNavBtns {
    
    self.navigationItem.leftBarButtonItem = [AppUtility getNavBtnItemLefBacktWith:@selector(leftNavBtnClicked) andTarget:self];
}
- (void)initViews {
    
//    self.forgetzf_btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    
//    self.Confirm_btn.layer.cornerRadius = 4.5;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(TapAction)];
    [self.view addGestureRecognizer:tap];
}
#pragma mark -
#pragma mark for evevts
#pragma mark -
- (void)leftNavBtnClicked {
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)TapAction {
    
    if ([_NewZF_textfiled isFirstResponder]) {
        [_NewZF_textfiled resignFirstResponder];
    }
    if ([_phone_textfiled isFirstResponder]) {
        [_phone_textfiled resignFirstResponder];
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)dealloc {
    [_phone_textfiled release];
    [_NewZF_textfiled release];
    [super dealloc];
}
- (IBAction)Confirm_btnClik:(UIButton *)sender {
    
    if ([AppUtility isBlankString:_phone_textfiled.text]) {
        //        [self.view makeToast:NSLocalizedString(@"oldpasskong", nil)];
        
        [self.view makeToast:@"手机号不能为空"];
        return;
    }
    if (![AppUtility checkTel:_phone_textfiled.text]) {
        return;
    }
    if ([AppUtility isBlankString:_NewZF_textfiled.text]) {
        //        [self.view makeToast:NSLocalizedString(@"newpasskong", nil)];
        [self.view makeToast:@"新支付密码不能为空"];
        
        return;
    }

    if ([_NewZF_textfiled.text length]<6) {
        
        //        [self.view makeToast:NSLocalizedString(@"newpassts", nil)];
        [self.view makeToast:@"新支付密码只能为6位数字" duration:1.0 position:@"center" title:nil image:[AppUtility getLocalImage:@"error"]];
        
        return;
        
    }
    
    if (![self inputShouldNumber:_NewZF_textfiled.text]) {
        //        [self.view makeToast:NSLocalizedString(@"newpassts", nil)];
        [self.view makeToast:@"新支付密码只能为6位数字" duration:1.0 position:@"center" title:nil image:[AppUtility getLocalImage:@"error"]];
        
        return;
    }
    NSString *postStr = @"";

    postStr = [NSString stringWithFormat:@"mobile=%@&password=%@",_phone_textfiled.text,_NewZF_textfiled.text];

    NSDictionary *resultDict =[NetUtility getDataWithURLStr:KURLSetNewZFPass andPostStr:postStr];

    UEXNSLog(@"kURL==%@%@ resultDict=%@",KURLSetNewZFPass,postStr,resultDict);

    if (resultDict) {
        int stauts = [[resultDict objectForKey:@"s"] intValue];

        if (stauts==1) {

            //            NSMutableDictionary *dic =[NSMutableDictionary dictionaryWithDictionary: [AccountController getAccountInfo]];
            //
            //            [dic setObject:textField.text forKey:@"nickname"];
            //            [AccountController setAccountInfo:dic];

            [self.navigationController popViewControllerAnimated:YES];

            [self.navigationController.view makeToast:[resultDict objectForKey:@"i"]];

        }else if (stauts == 303) {

            LoginViewController *vc = [[LoginViewController alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
            return;
        }

        [self.navigationController.view makeToast:[resultDict objectForKey:@"i"]];
    }
}

- (BOOL)inputShouldNumber:(NSString *)inputString {
    if (inputString.length == 0) return NO;
    NSString *regex =@"[0-9]*";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
    return [pred evaluateWithObject:inputString];
}
@end
